<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;

//后台登录控制器
class LoginController extends Controller{
	private $Model;
	//构造函数
	public function __init(){
//		后台登录页面数据库
		$this->Model = new \Common\Model\Admin_user;
	}
	
//后台登录页面
    public function index(){
//  	p($_POST);
//  	p($admin);
//  	p(md5('admin'));exit;
    	if(IS_POST){
    		
		$username = Q('post.admin_username');
//			p($username);
		$passwodr  = Q('post.admin_passwodr','','md5');
//			p($passwodr);exit;
    	$admin = $this->Model->where("admin_name='{$username}'")->find();
//			p($admin);exit;
			if($admin['admin_name'] != $username){
				
				View::error('用户名不存在');
			} 
			
			if($admin['admin_passwodr'] != $passwodr){
				
				View::error('密码不正确');
			}
			
			if($admin['admin_name'] == $username && $admin['admin_passwodr'] == $passwodr){
				
				$_SESSION['admin_uid'] = $admin['admin_uid'];
				
				$_SESSION['admin_name'] = $admin['admin_name'];
				
				View::success('登录成功',U('/Index/index',array('admin_uid'=>$_SESSION['admin_uid'])));
			}
    	}
//  	p(md5('home'));
       View::make();
    }
	
	

	
	
}
